source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-323.rds.xz")
summary(model)
SOM of size 10x10 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.425.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
547 1079 1482 1222 1865 1818 1254 1715 1698 1794 1458 1159 1098 1261 1546 1157
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
1669 1543 1587 1484 1521 1594 1370 1401 1408 774 1262 1240 1105 760 1559 1257
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
597 1464 1352 884 992 1179 1297 1350 1147 1153 1616 1071 860 665 977 1260
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
777 1426 1039 930 320 1364 1265 660 1018 1057 928 1452 1412 1417 1090 884
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
605 450 809 717 1105 1646 1043 74 836 486 777 185 418 495 1036 3
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
19 39 298 460 352 203 328 493 1118 1049 5 251 139 278 93 26
97 98 99 100
78 164 204 9
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 10*10;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "precip", "nevada", "prof_nieve")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin precip nevada prof_nieve
[1,] 0.91407932 0.3201151 0.3690164 -0.03192877 0.01480024 -0.03949785
[2,] 0.07691277 -0.7672002 -0.7197780 0.64363659 0.02387252 0.05783297
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
fecha_cnt tmin tmax precip prof_nieve nevada
0.9810094 0.9756455 0.9754580 0.9749566 0.9685620 0.9034467
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:148.0 1st Qu.: 53.00 1st Qu.: 3.00
Median : 6.000 Median :198.0 Median : 98.00 Median : 10.00
Mean : 6.497 Mean :200.2 Mean : 98.87 Mean : 16.25
3rd Qu.: 9.000 3rd Qu.:255.0 3rd Qu.: 148.00 3rd Qu.: 22.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0.00e+00 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.00e+00 1st Qu.: 0.0000 1st Qu.:38.28 1st Qu.: -5.6417
Median :0.00e+00 Median : 0.0000 Median :40.82 Median : -3.4500
Mean :3.16e-05 Mean : 0.3973 Mean :39.66 Mean : -3.4351
3rd Qu.:0.00e+00 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.4914
Max. :1.00e+00 Max. :892.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 247.0
Mean : 418.5
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.:148.0 1st Qu.: 53.0 1st Qu.: 3.00
Median : 6.000 Median :198.0 Median : 98.0 Median : 10.00
Mean : 6.498 Mean :200.3 Mean : 98.9 Mean : 16.24
3rd Qu.: 9.000 3rd Qu.:255.0 3rd Qu.: 148.0 3rd Qu.: 22.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0.00e+00 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0.00e+00 1st Qu.: 0.0000 1st Qu.:38.28 1st Qu.: -5.6417
Median :0.00e+00 Median : 0.0000 Median :40.82 Median : -3.4500
Mean :3.16e-05 Mean : 0.2746 Mean :39.66 Mean : -3.4350
3rd Qu.:0.00e+00 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.4914
Max. :1.00e+00 Max. :429.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 247.0
Mean : 418.2
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-12.00 Min. :-72.00 Min. : 19.00 Min. :0
1st Qu.:2.000 1st Qu.: 9.50 1st Qu.:-43.50 1st Qu.: 41.00 1st Qu.:0
Median :2.000 Median : 15.00 Median :-34.00 Median : 56.00 Median :0
Mean :2.368 Mean : 23.21 Mean :-31.95 Mean : 65.79 Mean :0
3rd Qu.:3.000 3rd Qu.: 28.50 3rd Qu.:-25.00 3rd Qu.: 82.00 3rd Qu.:0
Max. :4.000 Max. : 76.00 Max. : 8.00 Max. :180.00 Max. :0
prof_nieve longitud latitud altitud
Min. :465.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:531.0 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :606.0 Median :40.78 Median :-4.01 Median :1894
Mean :612.8 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:661.5 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :892.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-53.0 Min. :-121.0 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.:149.0 1st Qu.: 53.0 1st Qu.: 3.00 1st Qu.:0
Median : 6.000 Median :198.0 Median : 98.0 Median : 10.00 Median :0
Mean : 6.498 Mean :200.3 Mean : 98.9 Mean : 16.24 Mean :0
3rd Qu.: 9.000 3rd Qu.:255.0 3rd Qu.: 148.0 3rd Qu.: 22.00 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median : 0.0000 Median :40.82 Median : -3.4500 Median : 247.0
Mean : 0.2746 Mean :39.66 Mean : -3.4350 Mean : 418.2
3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :429.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :86.00 Min. :-24.0 Min. : 6.00 Min. :1
1st Qu.: 6.500 1st Qu.:86.00 1st Qu.:-19.5 1st Qu.: 6.00 1st Qu.:1
Median :12.000 Median :86.00 Median :-15.0 Median : 6.00 Median :1
Mean : 8.333 Mean :88.33 Mean : -7.0 Mean :10.33 Mean :1
3rd Qu.:12.000 3rd Qu.:89.50 3rd Qu.: 1.5 3rd Qu.:12.50 3rd Qu.:1
Max. :12.000 Max. :93.00 Max. : 18.0 Max. :19.00 Max. :1
prof_nieve longitud latitud altitud
Min. :0.0000 Min. :40.48 Min. :-3.450 Min. :263.0
1st Qu.:0.0000 1st Qu.:40.48 1st Qu.:-3.450 1st Qu.:435.6
Median :0.0000 Median :40.48 Median :-3.450 Median :608.1
Mean :0.3333 Mean :40.88 Mean :-2.644 Mean :493.1
3rd Qu.:0.5000 3rd Qu.:41.08 3rd Qu.:-2.242 3rd Qu.:608.1
Max. :1.0000 Max. :41.67 Max. :-1.033 Max. :608.1
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-12.00 Min. :-72.00 Min. : 19.00 Min. :0
1st Qu.:2.000 1st Qu.: 9.50 1st Qu.:-43.50 1st Qu.: 41.00 1st Qu.:0
Median :2.000 Median : 15.00 Median :-34.00 Median : 56.00 Median :0
Mean :2.368 Mean : 23.21 Mean :-31.95 Mean : 65.79 Mean :0
3rd Qu.:3.000 3rd Qu.: 28.50 3rd Qu.:-25.00 3rd Qu.: 82.00 3rd Qu.:0
Max. :4.000 Max. : 76.00 Max. : 8.00 Max. :180.00 Max. :0
prof_nieve longitud latitud altitud
Min. :465.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:531.0 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :606.0 Median :40.78 Median :-4.01 Median :1894
Mean :612.8 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:661.5 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :892.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.:149.0 1st Qu.: 53.00 1st Qu.: 3.00
Median : 6.000 Median :198.0 Median : 98.00 Median : 10.00
Mean : 6.499 Mean :200.3 Mean : 98.95 Mean : 16.23
3rd Qu.: 9.000 3rd Qu.:255.0 3rd Qu.: 148.00 3rd Qu.: 22.00
Max. :12.000 Max. :403.0 Max. : 254.00 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.0000 Min. :27.82 Min. :-17.8889
1st Qu.:0 1st Qu.: 0.0000 1st Qu.:38.28 1st Qu.: -5.6417
Median :0 Median : 0.0000 Median :40.82 Median : -3.4500
Mean :0 Mean : 0.1602 Mean :39.66 Mean : -3.4348
3rd Qu.:0 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.4914
Max. :0 Max. :194.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 42.0
Median : 247.0
Mean : 417.6
3rd Qu.: 656.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :86.00 Min. :-24.0 Min. : 6.00 Min. :1
1st Qu.: 6.500 1st Qu.:86.00 1st Qu.:-19.5 1st Qu.: 6.00 1st Qu.:1
Median :12.000 Median :86.00 Median :-15.0 Median : 6.00 Median :1
Mean : 8.333 Mean :88.33 Mean : -7.0 Mean :10.33 Mean :1
3rd Qu.:12.000 3rd Qu.:89.50 3rd Qu.: 1.5 3rd Qu.:12.50 3rd Qu.:1
Max. :12.000 Max. :93.00 Max. : 18.0 Max. :19.00 Max. :1
prof_nieve longitud latitud altitud
Min. :0.0000 Min. :40.48 Min. :-3.450 Min. :263.0
1st Qu.:0.0000 1st Qu.:40.48 1st Qu.:-3.450 1st Qu.:435.6
Median :0.0000 Median :40.48 Median :-3.450 Median :608.1
Mean :0.3333 Mean :40.88 Mean :-2.644 Mean :493.1
3rd Qu.:0.5000 3rd Qu.:41.08 3rd Qu.:-2.242 3rd Qu.:608.1
Max. :1.0000 Max. :41.67 Max. :-1.033 Max. :608.1
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-12.00 Min. :-72.00 Min. : 19.00 Min. :0
1st Qu.:2.000 1st Qu.: 9.50 1st Qu.:-43.50 1st Qu.: 41.00 1st Qu.:0
Median :2.000 Median : 15.00 Median :-34.00 Median : 56.00 Median :0
Mean :2.368 Mean : 23.21 Mean :-31.95 Mean : 65.79 Mean :0
3rd Qu.:3.000 3rd Qu.: 28.50 3rd Qu.:-25.00 3rd Qu.: 82.00 3rd Qu.:0
Max. :4.000 Max. : 76.00 Max. : 8.00 Max. :180.00 Max. :0
prof_nieve longitud latitud altitud
Min. :465.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:531.0 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :606.0 Median :40.78 Median :-4.01 Median :1894
Mean :612.8 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:661.5 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :892.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-12.00 Min. :-63.00 Min. : 5.00 Min. :0
1st Qu.: 1.500 1st Qu.: 14.00 1st Qu.:-38.00 1st Qu.:25.50 1st Qu.:0
Median : 2.000 Median : 28.00 Median :-26.00 Median :48.00 Median :0
Mean : 3.308 Mean : 31.95 Mean :-25.74 Mean :46.64 Mean :0
3rd Qu.: 3.500 3rd Qu.: 46.50 3rd Qu.:-15.00 3rd Qu.:66.50 3rd Qu.:0
Max. :12.000 Max. : 96.00 Max. : 28.00 Max. :92.00 Max. :0
prof_nieve longitud latitud altitud
Min. :197.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:227.5 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :269.0 Median :40.78 Median :-4.01 Median :1894
Mean :278.4 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:318.0 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :429.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-53 Min. :-121.00 Min. : 0.00 Min. :0
1st Qu.: 2.000 1st Qu.:122 1st Qu.: 28.00 1st Qu.: 6.00 1st Qu.:0
Median : 4.000 Median :156 Median : 59.00 Median : 14.00 Median :0
Mean : 5.912 Mean :152 Mean : 56.19 Mean : 19.76 Mean :0
3rd Qu.:11.000 3rd Qu.:184 3rd Qu.: 86.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.000 Max. :336 Max. : 219.00 Max. :126.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.47 1st Qu.: -5.3456 1st Qu.: 64.0
Median : 0.0000 Median :41.11 Median : -2.7331 Median : 412.0
Mean : 0.2758 Mean :40.41 Mean : -2.8404 Mean : 514.8
3rd Qu.: 0.0000 3rd Qu.:42.33 3rd Qu.: 0.4942 3rd Qu.: 750.0
Max. :194.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :153.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234.0 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :264.0 Median :154.0 Median : 5.000 Median :0
Mean : 7.205 Mean :265.4 Mean :155.9 Mean : 9.267 Mean :0
3rd Qu.: 9.000 3rd Qu.:294.0 3rd Qu.:181.0 3rd Qu.:15.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :53.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.19 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :40.07 Median : -3.6781 Median : 87.0
Mean : 0.00272 Mean :38.63 Mean : -4.1861 Mean : 291.3
3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 78.0 Min. :0
1st Qu.:10.000 1st Qu.:127.0 1st Qu.: 64.00 1st Qu.: 91.0 1st Qu.:0
Median :11.000 Median :149.0 Median : 84.00 Median :106.0 Median :0
Mean : 9.729 Mean :156.6 Mean : 88.43 Mean :116.6 Mean :0
3rd Qu.:12.000 3rd Qu.:182.0 3rd Qu.:111.00 3rd Qu.:131.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.0000 Median :42.43 Median : -5.598 Median : 127.0
Mean : 0.3505 Mean :41.28 Mean : -5.054 Mean : 299.2
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :81.0000 Max. :43.57 Max. : 4.216 Max. :2519.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :86.00 Min. :-24.0 Min. : 6.00 Min. :1
1st Qu.: 6.500 1st Qu.:86.00 1st Qu.:-19.5 1st Qu.: 6.00 1st Qu.:1
Median :12.000 Median :86.00 Median :-15.0 Median : 6.00 Median :1
Mean : 8.333 Mean :88.33 Mean : -7.0 Mean :10.33 Mean :1
3rd Qu.:12.000 3rd Qu.:89.50 3rd Qu.: 1.5 3rd Qu.:12.50 3rd Qu.:1
Max. :12.000 Max. :93.00 Max. : 18.0 Max. :19.00 Max. :1
prof_nieve longitud latitud altitud
Min. :0.0000 Min. :40.48 Min. :-3.450 Min. :263.0
1st Qu.:0.0000 1st Qu.:40.48 1st Qu.:-3.450 1st Qu.:435.6
Median :0.0000 Median :40.48 Median :-3.450 Median :608.1
Mean :0.3333 Mean :40.88 Mean :-2.644 Mean :493.1
3rd Qu.:0.5000 3rd Qu.:41.08 3rd Qu.:-2.242 3rd Qu.:608.1
Max. :1.0000 Max. :41.67 Max. :-1.033 Max. :608.1
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-12.00 Min. :-72.00 Min. : 19.00 Min. :0
1st Qu.:2.000 1st Qu.: 9.50 1st Qu.:-43.50 1st Qu.: 41.00 1st Qu.:0
Median :2.000 Median : 15.00 Median :-34.00 Median : 56.00 Median :0
Mean :2.368 Mean : 23.21 Mean :-31.95 Mean : 65.79 Mean :0
3rd Qu.:3.000 3rd Qu.: 28.50 3rd Qu.:-25.00 3rd Qu.: 82.00 3rd Qu.:0
Max. :4.000 Max. : 76.00 Max. : 8.00 Max. :180.00 Max. :0
prof_nieve longitud latitud altitud
Min. :465.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:531.0 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :606.0 Median :40.78 Median :-4.01 Median :1894
Mean :612.8 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:661.5 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :892.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-12.00 Min. :-63.00 Min. : 5.00 Min. :0
1st Qu.: 1.500 1st Qu.: 14.00 1st Qu.:-38.00 1st Qu.:25.50 1st Qu.:0
Median : 2.000 Median : 28.00 Median :-26.00 Median :48.00 Median :0
Mean : 3.308 Mean : 31.95 Mean :-25.74 Mean :46.64 Mean :0
3rd Qu.: 3.500 3rd Qu.: 46.50 3rd Qu.:-15.00 3rd Qu.:66.50 3rd Qu.:0
Max. :12.000 Max. : 96.00 Max. : 28.00 Max. :92.00 Max. :0
prof_nieve longitud latitud altitud
Min. :197.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:227.5 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :269.0 Median :40.78 Median :-4.01 Median :1894
Mean :278.4 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:318.0 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :429.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.00 Min. :-53.0 Min. :-121.00 Min. : 0.00 Min. :0
1st Qu.:2.00 1st Qu.:123.0 1st Qu.: 26.00 1st Qu.: 5.00 1st Qu.:0
Median :3.00 Median :155.0 Median : 56.00 Median : 13.00 Median :0
Mean :2.81 Mean :150.9 Mean : 51.64 Mean : 18.52 Mean :0
3rd Qu.:4.00 3rd Qu.:182.0 3rd Qu.: 80.00 3rd Qu.: 26.00 3rd Qu.:0
Max. :8.00 Max. :278.0 Max. : 178.00 Max. :126.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:39.01 1st Qu.: -5.4981 1st Qu.: 61.0
Median : 0.0000 Median :41.11 Median : -2.9056 Median : 370.0
Mean : 0.1288 Mean :40.36 Mean : -2.8768 Mean : 497.8
3rd Qu.: 0.0000 3rd Qu.:42.29 3rd Qu.: 0.4914 3rd Qu.: 704.0
Max. :60.0000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :153.0 Min. : 54.0 Min. : 0.000 Min. :0
1st Qu.: 6.000 1st Qu.:234.0 1st Qu.:131.0 1st Qu.: 1.000 1st Qu.:0
Median : 7.000 Median :264.0 Median :154.0 Median : 5.000 Median :0
Mean : 7.205 Mean :265.4 Mean :155.9 Mean : 9.267 Mean :0
3rd Qu.: 9.000 3rd Qu.:294.0 3rd Qu.:181.0 3rd Qu.:15.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :254.0 Max. :53.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.19 1st Qu.: -6.0556 1st Qu.: 32.0
Median : 0.00000 Median :40.07 Median : -3.6781 Median : 87.0
Mean : 0.00272 Mean :38.63 Mean : -4.1861 Mean : 291.3
3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 0.3664 3rd Qu.: 540.0
Max. :35.00000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. :-24.0 Min. :-110.00 Min. : 0.00 Min. :0
1st Qu.:10.00 1st Qu.:121.0 1st Qu.: 34.00 1st Qu.: 7.00 1st Qu.:0
Median :11.00 Median :158.0 Median : 67.00 Median : 16.00 Median :0
Mean :10.96 Mean :154.1 Mean : 63.86 Mean : 21.71 Mean :0
3rd Qu.:12.00 3rd Qu.:189.0 3rd Qu.: 95.00 3rd Qu.: 31.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. : 219.00 Max. :122.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.: 0.000 1st Qu.:39.49 1st Qu.: -5.2892 1st Qu.: 68.6
Median : 0.000 Median :41.15 Median : -2.7331 Median : 421.0
Mean : 0.105 Mean :40.50 Mean : -2.7771 Mean : 537.5
3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4942 3rd Qu.: 779.0
Max. :59.000 Max. :43.57 Max. : 4.2156 Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -2.00 Min. :-50.00 Min. : 0.00
1st Qu.: 1.000 1st Qu.: 28.25 1st Qu.:-27.75 1st Qu.: 21.25
Median : 3.000 Median : 40.00 Median :-21.00 Median : 37.50
Mean : 5.284 Mean : 44.77 Mean :-18.01 Mean : 40.65
3rd Qu.:11.000 3rd Qu.: 59.00 3rd Qu.: -6.25 3rd Qu.: 53.75
Max. :12.000 Max. :119.00 Max. : 30.00 Max. :126.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 62.00 Min. :40.35 Min. :-4.680 Min. : 900
1st Qu.:0 1st Qu.: 81.25 1st Qu.:40.78 1st Qu.:-4.010 1st Qu.:1894
Median :0 Median :103.50 Median :40.78 Median :-4.010 Median :1894
Mean :0 Mean :112.96 Mean :40.79 Mean :-3.960 Mean :1859
3rd Qu.:0 3rd Qu.:141.75 3rd Qu.:40.78 3rd Qu.:-4.010 3rd Qu.:1894
Max. :0 Max. :194.00 Max. :41.77 Max. :-1.117 Max. :1894
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : -8.0 Min. :-58.00 Min. : 78.0 Min. :0
1st Qu.:10.000 1st Qu.:127.0 1st Qu.: 64.00 1st Qu.: 91.0 1st Qu.:0
Median :11.000 Median :149.0 Median : 84.00 Median :106.0 Median :0
Mean : 9.729 Mean :156.6 Mean : 88.43 Mean :116.6 Mean :0
3rd Qu.:12.000 3rd Qu.:182.0 3rd Qu.:111.00 3rd Qu.:131.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. :223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:40.80 1st Qu.: -8.411 1st Qu.: 32.0
Median : 0.0000 Median :42.43 Median : -5.598 Median : 127.0
Mean : 0.3505 Mean :41.28 Mean : -5.054 Mean : 299.2
3rd Qu.: 0.0000 3rd Qu.:43.31 3rd Qu.: -2.039 3rd Qu.: 370.0
Max. :81.0000 Max. :43.57 Max. : 4.216 Max. :2519.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :86.00 Min. :-24.0 Min. : 6.00 Min. :1
1st Qu.: 6.500 1st Qu.:86.00 1st Qu.:-19.5 1st Qu.: 6.00 1st Qu.:1
Median :12.000 Median :86.00 Median :-15.0 Median : 6.00 Median :1
Mean : 8.333 Mean :88.33 Mean : -7.0 Mean :10.33 Mean :1
3rd Qu.:12.000 3rd Qu.:89.50 3rd Qu.: 1.5 3rd Qu.:12.50 3rd Qu.:1
Max. :12.000 Max. :93.00 Max. : 18.0 Max. :19.00 Max. :1
prof_nieve longitud latitud altitud
Min. :0.0000 Min. :40.48 Min. :-3.450 Min. :263.0
1st Qu.:0.0000 1st Qu.:40.48 1st Qu.:-3.450 1st Qu.:435.6
Median :0.0000 Median :40.48 Median :-3.450 Median :608.1
Mean :0.3333 Mean :40.88 Mean :-2.644 Mean :493.1
3rd Qu.:0.5000 3rd Qu.:41.08 3rd Qu.:-2.242 3rd Qu.:608.1
Max. :1.0000 Max. :41.67 Max. :-1.033 Max. :608.1
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :-12.00 Min. :-72.00 Min. : 19.00 Min. :0
1st Qu.:2.000 1st Qu.: 9.50 1st Qu.:-43.50 1st Qu.: 41.00 1st Qu.:0
Median :2.000 Median : 15.00 Median :-34.00 Median : 56.00 Median :0
Mean :2.368 Mean : 23.21 Mean :-31.95 Mean : 65.79 Mean :0
3rd Qu.:3.000 3rd Qu.: 28.50 3rd Qu.:-25.00 3rd Qu.: 82.00 3rd Qu.:0
Max. :4.000 Max. : 76.00 Max. : 8.00 Max. :180.00 Max. :0
prof_nieve longitud latitud altitud
Min. :465.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:531.0 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :606.0 Median :40.78 Median :-4.01 Median :1894
Mean :612.8 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:661.5 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :892.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-12.00 Min. :-63.00 Min. : 5.00 Min. :0
1st Qu.: 1.500 1st Qu.: 14.00 1st Qu.:-38.00 1st Qu.:25.50 1st Qu.:0
Median : 2.000 Median : 28.00 Median :-26.00 Median :48.00 Median :0
Mean : 3.308 Mean : 31.95 Mean :-25.74 Mean :46.64 Mean :0
3rd Qu.: 3.500 3rd Qu.: 46.50 3rd Qu.:-15.00 3rd Qu.:66.50 3rd Qu.:0
Max. :12.000 Max. : 96.00 Max. : 28.00 Max. :92.00 Max. :0
prof_nieve longitud latitud altitud
Min. :197.0 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:227.5 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :269.0 Median :40.78 Median :-4.01 Median :1894
Mean :278.4 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:318.0 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :429.0 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :2.0 Min. :-4.0 Min. :-51.0 Min. :19.0 Min. :0
1st Qu.:2.0 1st Qu.: 0.0 1st Qu.:-48.0 1st Qu.:33.0 1st Qu.:0
Median :3.0 Median :35.0 Median :-26.0 Median :49.0 Median :0
Mean :2.6 Mean :20.6 Mean :-32.8 Mean :41.4 Mean :0
3rd Qu.:3.0 3rd Qu.:36.0 3rd Qu.:-23.0 3rd Qu.:50.0 3rd Qu.:0
Max. :3.0 Max. :36.0 Max. :-16.0 Max. :56.0 Max. :0
prof_nieve longitud latitud altitud
Min. :1017 Min. :40.78 Min. :-4.01 Min. :1894
1st Qu.:1073 1st Qu.:40.78 1st Qu.:-4.01 1st Qu.:1894
Median :1168 Median :40.78 Median :-4.01 Median :1894
Mean :1317 Mean :40.78 Mean :-4.01 Mean :1894
3rd Qu.:1494 3rd Qu.:40.78 3rd Qu.:-4.01 3rd Qu.:1894
Max. :1834 Max. :40.78 Max. :-4.01 Max. :1894
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 69.00 Min. :-15.00 Min. : 3.00
1st Qu.: 2.000 1st Qu.: 76.00 1st Qu.: -5.00 1st Qu.: 9.00
Median : 2.000 Median : 91.00 Median : -1.00 Median :14.00
Mean : 5.222 Mean : 94.44 Mean : 10.89 Mean :12.89
3rd Qu.:12.000 3rd Qu.: 97.00 3rd Qu.: 30.00 3rd Qu.:15.00
Max. :12.000 Max. :140.00 Max. : 35.00 Max. :24.00
nevada prof_nieve longitud latitud
Min. :2.000 Min. : 0.000 Min. :40.48 Min. :-3.450
1st Qu.:2.000 1st Qu.: 0.000 1st Qu.:40.48 1st Qu.:-3.450
Median :2.000 Median : 1.000 Median :41.67 Median :-1.033
Mean :2.778 Mean : 3.111 Mean :41.14 Mean :-2.107
3rd Qu.:3.000 3rd Qu.: 5.000 3rd Qu.:41.67 3rd Qu.:-1.033
Max. :6.000 Max. :13.000 Max. :41.67 Max. :-1.033
altitud
Min. :263.0
1st Qu.:263.0
Median :263.0
Mean :416.4
3rd Qu.:608.1
Max. :608.1
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)